import request from "utils/request";

const state = {
  userInfo: {},
};

const mutations = {
  updateUser(state, userInfo) {
    state.userInfo = userInfo;
  },
  clearUserInfo() {
    state.userInfo = {}
  }
};

const actions = {
  getUserInfo({ commit }) {
    return new Promise((resolve, reject) => {
      request.get("/user/self").then((ret) => {
        console.log("🚀 ~ file: user.js:20 ~ request.get ~ ret", ret)
        if (ret.code == 200) {
          commit("updateUser", ret.data);
          resolve(ret.data);
        } else {
          reject(ret.message);
        }
      });
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
